const webpack = require('webpack');
const BASE_URL = "/";
const path = require("path");
const timeStamp = new Date().getTime();
function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  publicPath: BASE_URL,
  pluginOptions: {
    electronBuilder: {
        preload:'src/preload.js',
        customFileProtocol: './',
        // electronPort:"8000",
        builderOptions: {
            "appId": "com.tailanoa.app",
            "productName":"太蓝云桌面",//项目名，也是生成的安装文件名，即aDemo.exe
            "copyright":"Copyright © 2022",//版权信息
            "win": {
              "target": [
                {
                  "target": "nsis",
                  "arch": [
                    "x64",
                    "ia32"
                  ]
                }
              ],
              "icon":"./256.png"
            },
            "mac":{
              "target":"dmg"
              //  "target":{
              //     "target":"dmg",
              //     "arch":["arm64","x64"]
              //  }
            },
            "dmg":{
              "background":"#fff"
            },
            "nsis": {
                "installerIcon": "./logo.ico",  // 安装图标
                "uninstallerIcon": "./logo.ico",  // 卸载图标
                "installerHeaderIcon": "./logo.ico",  // 安装时头部图标
                "oneClick": false, // 是否一键安装
                "allowElevation": true, // 允许请求提升。 如果为false，则用户必须使用提升的权限重新启动安装程序。
                "allowToChangeInstallationDirectory": true, // 允许修改安装目录
              },
            }
        }

  },
  devServer: {
    overlay: false,
    port: 8088 
  },
  css: {
    sourceMap: true, 
    extract: {
      filename: `[name].${timeStamp}.css`,
      chunkFilename: `[name].${timeStamp}.css`
    }
  },
  lintOnSave: false,
  productionSourceMap: false,
  configureWebpack: {
    plugins: [
      new webpack.optimize.LimitChunkCountPlugin({
        maxChunks:5,
        minChunkSize:100
      })
    ],
    output: {
      filename: `[name].${timeStamp}.js`,
      chunkFilename: `[name].${timeStamp}.js`
    },
    externals: {
      vue: "Vue",
      "vue-router": "VueRouter",
      "element-ui": "ELEMENT"
    },
    resolve: {
      alias: {
        "@xjr": "@/components/xjr"
      }
    },
    optimization: {
      splitChunks: {
        chunks: "async", 
        minSize: 400000,
        maxSize: 0, 
        minChunks: 1, 
        maxAsyncRequests: 5,
        maxInitialRequests: 3, 
        automaticNameDelimiter: "~", 
        name: true,
        cacheGroups: {
          vendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10
          },
          default: {
            minChunks: 2,
            priority: -20,
            reuseExistingChunk: true
          }
        }
      }
    }
  },
  chainWebpack: config => {
    config.module
      .rule("svg")
      .exclude.add(resolve("src/icons"))
      .end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      })
      .end();
    config.externals({
      vue: "Vue",
      "vue-router": "VueRouter",
      vuex: "Vuex",
      axios: "axios",
      "element-ui": "ELEMENT"
    });
    const entry = config.entry("app");
    entry.add("babel-polyfill").end();
    entry.add("classlist-polyfill").end();
    entry.add("@/mock").end();
  }
};
